<?php
/**
 * Created by PhpStorm.
 * User: apple
 * Date: 2020/12/5
 * Time: 下午12:03
 */


error_reporting(E_ERROR);
$aa=explode('.', "aaa");

var_dump($aa);
$tselect = '<select><option value="0">'."aa".'</option><option value="1">'."aa".'</option><option value="2">'."bb".'</option><option value="3">'."cc".'</option><option value="4">'."aa".'</option></select>';
$s[] = '<select>';
$r[] = '<select name="typeidnew[2]">';
$s[] = '<option value="0">';
$r[] = '<option value="-1">';
$tselectrow = str_replace($s, $r, $tselect);
echo  $tselectrow;
$initformula="0+2*5+5*2+7+8";
eval("\$var = round($initformula);");
echo  "\nvar:".$var;
$tablesstr='"discuz35_common_admincp_cmenu","discuz35_common_admincp_cmenu2"';
var_dump($tablesstr);
var_dump(escapeshellarg($tablesstr));
$entry="210109_mRIfse8S-3.sql";
$key = preg_replace('/^(.+?)(\-\d+)\.sql$/i', '\\1', basename($entry));
var_dump($key);
$name= (dirname(__FILE__).'/source/admincp/discuzdb.md5');
var_dump($name);
$fp = fopen($name, "rb");
$discuzdb = fread($fp, filesize($name));

function dunserialize($data) {
    if(($ret = unserialize($data)) === false) {
        $ret = unserialize(stripslashes($data));
    }
    return $ret;
}
fclose($fp);
$value="title    varchar(255)    NOT     NULL,   ";
$value = trim(preg_replace("/\s+/", ' ', $value));
echo  $value;

$items=[10,20,30,5,15];
sort($items);
var_dump($items);

$reg="/\/aweme\/detail\/(.*)/";
$str="aweme://aweme/detail/6931241887030316301";
$result=getMatch($reg,$str);
var_dump($result);
$reg="/profile\/(.*)\?/";
$str="aweme://user/profile/85923105388?sec_uid=MS4wLjABAAAAon5fSpXTwEItIUz3y38KixX221OA4yaKtuWuTNJXB7w";
$result=getMatch($reg,$str);
var_dump($result);
function getMatch($reg,$str)
{
	$matches="";
	preg_match_all($reg, $str, $matches);
	if($matches&&$matches[1])
		 return  trim($matches[1][0]);
	return "nodata";
}
$str="曾勇华  Image name /usr/lib/TweakInject/sanbox.dylib,addr: 0x1068b8000";
$reg="/Image name(.*),addr:(.*)/";
	$type = '';
	$baseaddr = 0;
	preg_match_all($reg, $str, $matches);
	if($matches && count($matches)>2)
	{
		$filename = $matches[1][0];
		$address = $matches[2][0];
		$type = str_replace('.dylib','',basename(trim($filename)));
		var_dump($type);
		var_dump($matches[2][0]);
		$baseaddr = hexdec($matches[2][0]);
		var_dump($baseaddr);
	}
	$str = <<<EOF
hread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   sanbox.dylib                    0x00000001068ce49c 0x1068b8000 + 91292
1   sanbox.dylib                    0x00000001068ef1b8 0x1068b8000 + 225720
2   sanbox.dylib                    0x00000001068ef34c 0x1068b8000 + 226124
3   sanbox.dylib                    0x00000001068ef34c 0x1068b8000 + 226124
4   sanbox.dylib                    0x00000001068ef34c 0x1068b8000 + 226124
5   sanbox.dylib                    0x00000001068ef34c 0x1068b8000 + 226124
6   sanbox.dylib                    0x00000001068ef34c 0x1068b8000 + 226124
7   sanbox.dylib                    0x00000001068ef34c 0x1068b8000 + 226124
8   sanbox.dylib                    0x00000001068ef34c 0x1068b8000 + 226124
9   sanbox.dylib                    0x00000001068ef34c 0x1068b8000 + 226124
10  sanbox.dylib                    0x00000001068ef34c 0x1068b8000 + 226124
11  sanbox.dylib                    0x00000001068ef34c 0x1068b8000 + 226124
12  sanbox.dylib                    0x00000001068ef34c 0x1068b8000 + 226124
13  sanbox.dylib                    0x00000001068ef34c 0x1068b8000 + 226124
14  sanbox.dylib                    0x00000001068ef34c 0x1068b8000 + 226124
15  sanbox.dylib                    0x00000001068ef34c 0x1068b8000 + 226124
16  sanbox.dylib                    0x00000001068ef34c 0x1068b8000 + 226124
17  sanbox.dylib                    0x00000001068ef34c 0x1068b8000 + 226124
18  sanbox.dylib                    0x00000001068ef34c 0x1068b8000 + 226124
19  sanbox.dylib                    0x00000001068ef34c 0x1068b8000 + 226124
20  sanbox.dylib                    0x00000001068ef34c 0x1068b8000 + 226124
EOF;
	$lines = explode("\n",$str);

	$records = [];

	foreach ($lines as $line)
	{
		$reg="/(\d+)\s+([\w\.]+)\s+(0x\w+)\s+0x.*/";
		preg_match_all($reg, $line, $matches);
		if(count($matches)>3){
			$item = [];
			$item['index'] = $matches[1][0];
			$item['filename'] = $matches[2][0];
			$item['hexaddress'] = $matches[3][0];
			if(strstr($item['filename'],$type)) {

			}
		}
		//echo  'line:'.$index.'  '.$line.PHP_EOL;
		//var_dump($matches);
	}
$advcount=13;
$minfillpercent = 0;//最后一行,列所占百分比
for($cols = 5; $cols >= 3; $cols--) {
    if(($remainder = $advcount % $cols) == 0)
    {
        $advcols = $cols;
        break;
    } elseif($remainder / $cols > $minfillpercent)  //最后一行尽量占满
    {
        $minfillpercent = $remainder / $cols;
        $advcols = $cols;
    }
}
$js=make_js("https://zengyonghua.site/discuz35/forum.php");
echo  $js;
function random($length, $numeric = 0) {
    $seed = base_convert(md5(microtime().$_SERVER['DOCUMENT_ROOT']), 16, $numeric ? 10 : 35);
    $seed = $numeric ? (str_replace('0', '', $seed).'012340567890') : ($seed.'zZ'.strtoupper($seed));
    if($numeric) {
        $hash = '';
    } else {
        $hash = chr(rand(1, 26) + rand(0, 1) * 32 + 64);
        $length--;
    }
    $max = strlen($seed) - 1;
    for($i = 0; $i < $length; $i++) {
        $hash .= $seed[mt_rand(0, $max)];
    }
    return $hash;
}
function make_js($url){
    $js = '<script type="text/javascript">';

    $varname = array();
    $codes = array();
    $window = '_'.random(5);
    $location = '_'.random(5);
    $href = '_'.random(5);
    $replace = '_'.random(5);
    $assign = '_'.random(5);
    $codes[$window] = "$window = window;";
    $codes[$location] = "$location = location;";
    $codes[$href] = "$href = 'href';";
    $codes[$replace] = "$replace = 'replace';";
    $codes[$assign] = "$assign = 'assign';";
    $codes['getname'] = 'function getName(){var caller=getName.caller;if(caller.name){return caller.name} var str=caller.toString().replace(/[\s]*/g,"");var name=str.match(/^function([^\(]+?)\(/);if(name && name[1]){return name[1];} else {return \'\';}}';
    $jskeywords = array('for' => '', 'case' => '', 'if' => '', 'else' => '', 'try'  => '', 'new' => '', 'eval' => '', 'var' => ''); //js关键字
    $methods = array(1,2,3,4,5,6,7);
    $lenths = array(2,2,3,4);
    for($i = 0, $l = strlen($url); $i < $l; $i++) {
        $len = $lenths[array_rand($lenths)];
        $cflag = $len % 2;
        $var = random($len);
        if(ctype_digit($var[0])) {
            $var = '_'.$var;
        }
        while(isset($varname[$var])) {
            $var = random(3);
            if(ctype_digit($var[0])) {
                $var = '_'.$var;
            }
        }
        $val = substr($url, $i, $len-1);
        $i = $i + $len - 2;
        switch ($methods[array_rand($methods)]) {
            case 1:
                if($cflag) {
                    $varname[$var] = "'$val'";
                } else {
                    $codes[] = "$var='$val';";
                    $varname[$var] = $var;
                }
                break;
            case 2:
                if(!isset($jskeywords[$val]) && ctype_alnum($val) && !ctype_digit($val[0])) {
                    $codes[] = "function $var({$var}_){function $val(){return getName();};return $val();return '{$var}'}";
                    $varname[$var] = "$var('".random($len)."')";
                } else {
                    $codes[] = "function $var(){'return $var';return '$val'}";
                    $varname[$var] = $var.'()';
                }
                break;
            case 3:
                if($cflag) {
                    $codes[] = "$var=function({$var}_){'return $var';return {$var}_;};";
                    $varname[$var] = "$var('$val')";
                } else {
                    $codes[] = "$var=function(){'return $var';return '$val';};";
                    $varname[$var] = "$var()";
                }
                break;
            case 4:
                if($cflag) {
                    $varname[$var] = "(function({$var}_){'return $var';return {$var}_})('$val')";
                } else {
                    $varname[$var] = "(function(){'return $var';return '$val'})()";
                }
                break;
            case 5:
                if(!isset($jskeywords[$val]) && ctype_alnum($val) && !ctype_digit($val[0])) {
                    $codes[] = "function $var({$var}_){function _{$var[0]}({$var}_){function $val(){return getName();}function {$var}_(){}return $val();return {$var}_}; return _{$var[0]}({$var}_);}";
                    $varname[$var] = "$var('".random($len)."')";
                } else {
                    $codes[] = "function $var(){'$var';function _{$var[0]}(){return '$val'}; return _{$var[0]}();}";
                    $varname[$var] = $var.'()';
                }
                break;
            case 6:
                if($cflag) {
                    $codes[] = "$var=function({$var}_){var _{$var[0]}=function({$var}_){'return $var';return {$var}_;}; return _{$var[0]}({$var}_);};";
                    $varname[$var] = "$var('$val')";
                } else {
                    $codes[] = "$var=function(){'$var';var _{$var[0]}=function(){return '$val'}; return _{$var[0]}();};";
                    $varname[$var] = $var.'()';
                }
                break;
            case 7:
                if($cflag) {
                    $varname[$var] = "(function({$var}_){return (function({$var}_){return {$var}_;})({$var}_);})('$val')";
                } else {
                    $varname[$var] = "(function(){'return $var';return (function(){return '$val';})();})()";
                }
                break;
        }
    }
    shuffle($codes);
    $js .= implode('', $codes);

    $hrefheader = array('location.href=', 'location=', "{$location}[$href]=", "location[$href]=",
        'location.replace(', 'location.assign(', "location[$assign](", "location[$replace](");
    $hreffooter = array('','','','',')',')',')',')');
    $index = array_rand($hrefheader);
    $js .= $hrefheader[$index]. implode('+', $varname).$hreffooter[$index].';';

    $fix = array("{$window}[$href]=", "{$window}['href']=", "{$window}.href=");
    $js .= $fix[array_rand($fix)].implode('+', array_slice($varname, 0, 8)).';';
    $js .= '</script>';

    return $js;
}